package com.jave;


import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.InputFormatException;
import it.sauronsoftware.jave.MultimediaInfo;
import it.sauronsoftware.jave.VideoAttributes;
import it.sauronsoftware.jave.VideoSize;

import java.io.File;
import java.util.Scanner;

/**
 * Hello world!
 *
 */
public class App 
{
//	 private static final String filename = "c:/myvideo.mp4";

	    public static void main(String[] args) throws IllegalArgumentException, InputFormatException, EncoderException {
	    	Scanner scanner = new Scanner(System.in);
	    	System.out.println("输入1:视频转换,2：音频转换,3:截屏");
	    	int num = scanner.nextInt();
	    	System.out.println("输入原文件地址");
	    	String source = scanner.next();
	    	System.out.println("输入转换后文件保存地址");
	    	String target = scanner.next();
	    	
	    	if(num == 1){
	    		encode_video(source,target);
	    	}else if(num ==2){
	    		encode_audio(source,target);
	    	}else{
	    		encode_video_image(source,target);
	    	}
	    	

	        
	    }
	    
	    private static void encode_video(String source,String target) throws InputFormatException, EncoderException{
	    	Encoder encoder = new Encoder();
	    	MultimediaInfo info =  encoder.getInfo(new File(source));
	    	 //设置音频参数
	        AudioAttributes audio = new AudioAttributes();
//	        audio.setCodec("libmp3lame");
//	        audio.setBitRate(info.getAudio().getBitRate());
//	        audio.setChannels(info.getAudio().getChannels());
//	        audio.setCodec(info.getAudio().getDecoder());
//	        audio.setSamplingRate(info.getAudio().getSamplingRate());
	        
	        //设置视频参数
	        VideoAttributes video = new VideoAttributes();
	        video.setCodec("mpeg4"); //-vcodec
//	        video.setBitRate(info.getVideo().getBitRate());
//	        video.setFrameRate(Integer.parseInt(info.getVideo().getFrameRate());
	        VideoSize size = new VideoSize(300,180);
	        video.setSize(size);
	        
	        
	        //设置转换器参数
	        EncodingAttributes attrs = new EncodingAttributes();
	        attrs.setFormat("mp4");//-f
	        attrs.setAudioAttributes(audio);
	        attrs.setVideoAttributes(video);
	       
//	        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getDuration());
//	        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getBitRate());
//	        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getSamplingRate());
//	        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getChannels());
//	        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getDecoder());
	        System.out.println("encoding....");
	        encoder.encode(new File(source), new File(target), attrs);
	        System.out.println("end!");
	    }
	    
	    private static void encode_video_image(String source,String target) throws InputFormatException, EncoderException{
	    	Encoder encoder = new Encoder();
	    	MultimediaInfo info =  encoder.getInfo(new File(source));
	    	 //设置音频参数
	        AudioAttributes audio = new AudioAttributes();
//	        audio.setCodec("libmp3lame");
//	        audio.setBitRate(info.getAudio().getBitRate());
//	        audio.setChannels(info.getAudio().getChannels());
//	        audio.setCodec(info.getAudio().getDecoder());
//	        audio.setSamplingRate(info.getAudio().getSamplingRate());
	        
	        //设置视频参数
	        VideoAttributes video = new VideoAttributes();
	        video.setSize(info.getVideo().getSize());
	        
	        
	        //设置转换器参数
	        EncodingAttributes attrs = new EncodingAttributes();
	        attrs.setFormat("image2");//-f
	        attrs.setDuration(0.01f);
//	        attrs.setAudioAttributes(audio);
	        attrs.setVideoAttributes(video);
	       
//	        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getDuration());
//	        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getBitRate());
//	        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getSamplingRate());
//	        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getChannels());
//	        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getDecoder());
	        System.out.println("encoding....");
	        encoder.encode(new File(source), new File(target), attrs);
	        System.out.println("end!");
	    }
	    
	    private static void encode_audio(String source,String target) throws InputFormatException, EncoderException{
	    	 Encoder encoder = new Encoder();
		    	MultimediaInfo info =  encoder.getInfo(new File(source));
		    	 //设置音频参数
		        AudioAttributes audio = new AudioAttributes();
//		        audio.setCodec("libmp3lame");
//		        audio.setBitRate(info.getAudio().getBitRate());
//		        audio.setChannels(info.getAudio().getChannels());
//		        audio.setCodec(info.getAudio().getDecoder());
//		        audio.setSamplingRate(info.getAudio().getSamplingRate());
		        
		        //设置视频参数
//		        VideoAttributes video = new VideoAttributes();
//		        video.setCodec("mpeg4"); //-vcodec
//		        video.setBitRate(info.getVideo().getBitRate());
//		        video.setFrameRate(Integer.parseInt(info.getVideo().getFrameRate());
//		        video.setSize(info.getVideo().getSize());
		        
		        
		        //设置转换器参数
		        EncodingAttributes attrs = new EncodingAttributes();
		        attrs.setFormat("mp3");//-f
		        attrs.setAudioAttributes(audio);
		        attrs.setVideoAttributes(null);
		       
//		        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getDuration());
//		        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getBitRate());
//		        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getSamplingRate());
//		        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getChannels());
//		        System.out.println(encoder.getInfo(new File("D:\\file\\default\\201802\\audio\\o\\6396696875634688.aac")).getAudio().getDecoder());
		        System.out.println("encoding....");
		        encoder.encode(new File(source), new File(target), attrs);
		        System.out.println("end!");
	    }
	    
	   

}
